<template>
    <div>
        <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="菜单名称">
      <el-input v-model="form.name" />
    </el-form-item>
    <el-form-item label="菜单路径">
      <el-input v-model="form.href" />
    </el-form-item>
    <el-form-item label="上级菜单">
      <el-select v-model="form.parentId" placeholder="please select your zone">
        <el-option label="顶级菜单" :value="-1" />
        <el-option v-for="menu in topMenus" :key="menu.id"  :label=" menu.name" :value="menu.id" />
      </el-select>
      
    </el-form-item>
    <el-form-item label="描述">
      <el-input v-model="form.description" />
    </el-form-item>
      <el-form-item label="图标名称">
      <el-input v-model="form.icon" />
    </el-form-item>
    <el-form-item label="是否显示">
      <el-radio-group v-model="form.shown">
        <el-radio :value="true">是</el-radio>
        <el-radio :value="false">否</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="排序">
      <el-input v-model="form.orderNum" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
    </el-form-item>
  </el-form>
    </div>
</template>

<script setup lang="ts">
import { useMenus } from '@/composables/useMenus';
const {getAllMenus,onSubmit,form,topMenus}=useMenus()   //调用后，解构到想要得到的值
getAllMenus()



// import { getAll,saveOrUpdateMenu } from '@/api/menus';
// import type { MenuItem } from '@/api/menus';
// import { ref,computed } from 'vue';
// import { ElMessage } from 'element-plus';
// const allMenus=ref([] as MenuItem[])

// const getAllMenus=async ()=>{
//     const {data}=await getAll()
//     if(data.code === "000000"){
//         menus.value=res.data.data
//     }else{
//         ElMessage.error("获取菜单列表失败")
//         throw new Error("获取菜单列表失败")
//     }
// }
// getAllMenus()

// // 获取顶级菜单筛选的逻辑
// const topMenus=computed(()=>{
//     menus.value.filter(menu=>menu.level === '0')
// })
</script>

<style scoped></style>
 